﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;

namespace Utilities
{
    public class LogMessageFactory
    {
        public LogMessageFactory()
        {
            Values = new Dictionary<string, object>();
        }

        public enum Severities
        {
            Information = 0,
            Warning,
            Error
        }

        public Severities Severity { get; set; }

        public string Key { get; set; }

        public string Text { get; set; }

        /// <summary>
        /// The values to substitute in the template
        /// </summary>
        public IDictionary<string, object> Values { get; set; }

        public LogMessage Create(string locale = null)
        {
            //Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(locale);

            Template template = new Template
            {
                Text = this.Text // TODO: Get text from 
            };

            return new LogMessage
            {
                Severity = Severity,
                SeverityString = GetSeverityString(locale),
                Text = template.Apply(Values)
            };
        }

        private string GetSeverityString(string locale)
        {
            switch (Severity)
            {
                case Severities.Error: return "Error";
                case Severities.Warning: return "Warning";
                default: return "Information";
            }
        }
    }
}
